<?
function email_form(){
	//includes
	echo '<script src="{base_url}system/livevalidation/livevalidation.js" type="text/javascript"></script>
	<script src="{base_url}system/ext/adapter/prototype/prototype.js" type="text/javascript"></script>';
	//form
	echo '<form id="email-form">
	Name<br />
	<input type="text" name="name" id="name" value="" size="30"  />
	<br />
	Email (will never be published)<br />
	<input type="text" name="email" id="email" value="" size="30"  />
	<br />
	Message<br />
	<textarea name="message" id="message" cols="40" rows="7" ></textarea>
	<br />
	<input type="button" id="subbut" name="subbut" value="Send" onclick="submitForm();"  /> 
	<input type="button" id="resetbut" name="resetbut" value="Reset" onclick="resetForm();"  />
	</form>
	<br />
	<div id="sentDiv"></div>';
	//validation and ajax
	echo '<script type="text/javascript">
	var name = new LiveValidation( \'name\' );
	name.add( Validate.Presence );
	var email = new LiveValidation( \'email\' );
	email.add( Validate.Presence );
	email.add( Validate.Email );
	// get the form
	var form = document.getElementById( \'email-form\' );
	
	function submitForm(){
		if(LiveValidation.massValidate( [ name, email ] )){
			var params = Form.serialize(\'email-form\');
			new Ajax.Request(\'{base_theme}email-form.php\', {
			method:\'post\',
			asynchronous:true, 
			parameters:params,
			onLoading: function(){
				$("subbut").value = \'Sending...\';
			},
		    onSuccess: function(transport){
		      var response = transport.responseText || "no response text";
		      //alert("Success! \n\n" + response);
			  $("subbut").value = \'Send\';
			  $("sentDiv").innerHTML = \'<b>Email successfully sent!</b>\';
			  $("name").disabled = "disabled";
			  $("email").disabled = "disabled";
			  $("message").disabled = "disabled";
			  $("subbut").disabled = "disabled";
		    },
		    onFailure: function(){ 
				$("subbut").value = \'Failed to Send\'; 
				$("sentDiv").innerHTML = \'<b>Email failed to send!</b>\';
			}
			});
		}
	}
	
	function resetForm(){
		$("name").disabled = "";
		$("email").disabled = "";
		$("message").disabled = "";
		$("subbut").disabled = "";
		$("sentDiv").innerHTML = "";
		$("name").value = "";
		$("email").value = "";
		$("message").value = "";
		$("subbut").value = "Send";
	}
	</script>';
}
?>